package signature

import (
	"go-caipu/pkg/plugins"
	"go-caipu/pkg/setting"
)

func ProvideOSSAuthorizer(cfg *setting.Cfg) *UnsignedPluginAuthorizer {
	return &UnsignedPluginAuthorizer{
		cfg: cfg,
	}
}

type UnsignedPluginAuthorizer struct {
	cfg *setting.Cfg
}

// CanLoadPlugin 验证是否能加载插件
func (u *UnsignedPluginAuthorizer) CanLoadPlugin(p *plugins.Plugin) bool {
	if p.Signature != plugins.SignatureUnsigned {
		return true
	}

	if u.cfg.Application.Mode == "development" {
		return true
	}
	for _, pID := range u.cfg.PluginCfg.PluginsAllowUnsigned {
		if pID == p.ID {
			return true
		}
	}
	return false
}
